package com.usdt.system.service.impl.cp;

import java.util.List;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.usdt.system.cp.utils.UserAndDeptUtils;
import com.usdt.system.domain.cp.ClueCustomerInfoEntity;
import com.usdt.system.domain.cp.VisitCustomerInfoEntity;
import com.usdt.system.mapper.cp.VisitCustomerInfoMapper;
import com.usdt.system.service.cp.VisitCustomerInfoService;

/**
 * <p>
 * 到访-客户信息 服务实现类
 * </p>
 *
 * @author L
 * @since 2025-10-05
 */
@Service
public class VisitCustomerInfoServiceImpl extends ServiceImpl<VisitCustomerInfoMapper, VisitCustomerInfoEntity> implements VisitCustomerInfoService {

	@Override
	public List<VisitCustomerInfoEntity> checkVisitCustomerInfoUniqueByDeptIdAndPhoneNumber(String deptId,
			String phoneNumber, Integer id) {
		
		return baseMapper.checkVisitCustomerInfoUniqueByDeptIdAndPhoneNumber(deptId,phoneNumber,id);
	}
	
	@Override
	public List<VisitCustomerInfoEntity> getVisitCustomerInfoByVisitId(Integer visitId) {
		QueryWrapper<VisitCustomerInfoEntity> query = new QueryWrapper<VisitCustomerInfoEntity>();
		query.eq("is_del", false).eq("visit_id", visitId);
		
		return baseMapper.selectList(query);
	}
	
	@Override
	public void delByVisitId(Integer visitId) {
		QueryWrapper<VisitCustomerInfoEntity> query = new QueryWrapper<VisitCustomerInfoEntity>();
		query.eq("is_del", false).eq("visit_id", visitId);
		
		baseMapper.delete(query);
	}

	@Override
	public void transferOut(Integer visitid, String outUserId, String outDeptId, String currentUserId) {
		VisitCustomerInfoEntity entity = new VisitCustomerInfoEntity();
		entity.setCreateBy(outUserId);
		entity.setDeptId(outDeptId);
		entity.setUpdateBy(currentUserId);
		
		QueryWrapper<VisitCustomerInfoEntity> query  = new QueryWrapper<VisitCustomerInfoEntity>();
		query.eq("visit_id", visitid);
		baseMapper.update(entity , query);
	}

	@Override
	public void batchTransferOut(List<Integer> visitIds, String outUserId, String outDeptId) {
		QueryWrapper<VisitCustomerInfoEntity> query = new QueryWrapper<VisitCustomerInfoEntity>();
		query.eq("is_del", false).in("visit_id", visitIds);
		
		VisitCustomerInfoEntity visitCustomerInfoEntity = new VisitCustomerInfoEntity();
		visitCustomerInfoEntity.setDeptId(outDeptId);
		visitCustomerInfoEntity.setCreateBy(outUserId);
		visitCustomerInfoEntity.setUpdateBy(UserAndDeptUtils.getCurrentUserId());
		baseMapper.update(visitCustomerInfoEntity, query);
	}
}
